<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\SchoolAnli;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

use Illuminate\Http\Request;
use App\Models\SchoolAnli as SchoolAnliModel;

class SchoolAnliController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new SchoolAnliModel(), function (Grid $grid) {
            $grid->model()->with(['school']);
            $grid->column('school.school_name');
            $grid->column('country_id')->editable();
            $grid->column('name')->editable();
            $grid->column('graduation_school')->editable();
            $grid->column('enter_school_id')->editable();
            $grid->column('japanese_scores')->editable();
            $grid->column('enter_time')->editable();
            $grid->column('apply_degree')->editable();
            $grid->column('apply_major')->editable();
            $grid->column('gpa')->editable();
            $grid->column('toefl')->editable();
            $grid->column('ielts')->editable();
            $grid->column('gre')->editable();
            $grid->column('school_row')->editable();
            $grid->column('status')->editable();
            $grid->column('sort')->editable();
    $grid->quickSearch('country_id','name','graduation_school','enter_school_id','japanese_scores','enter_time','apply_degree','apply_major','gpa','toefl','ielts','gre','school_row','status','sort');

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new SchoolAnliModel(), function (Show $show) {
            $show->id;
            $show->country_id;
            $show->name;
            $show->graduation_school;
            $show->enter_school_id;
            $show->japanese_scores;
            $show->enter_time;
            $show->apply_degree;
            $show->apply_major;
            $show->gpa;
            $show->toefl;
            $show->ielts;
            $show->gre;
            $show->school_row;
            $show->status;
            $show->sort;
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new SchoolAnliModel(), function (Form $form) {
            $form->display('id');
            $form->text('country_id');
            $form->text('name');
            $form->text('graduation_school');
            $form->text('enter_school_id');
            $form->text('japanese_scores');
            $form->text('enter_time');
            $form->text('apply_degree');
            $form->text('apply_major');
            $form->text('gpa');
            $form->text('toefl');
            $form->text('ielts');
            $form->text('gre');
            $form->text('school_row');
            $form->text('status');
            $form->text('sort');
        });
    }

    /**
     * [listType 下拉关联查询]
     * @return [type] [description]
     */
    public function listType()
    {
        $request = new Request();
        $q = $request->get('q');
        return SchoolAnliModel::where('type_name', 'like', "%$q%")->select('type_id as id', 'type_name as text')->get();
    }

}
